#include "LuaLink_RaySceneQuery.h"

LuaLink_RaySceneQuery::LuaLink_RaySceneQuery(Ogre::RaySceneQuery* raySceneQuery) {
	mRaySceneQuery = raySceneQuery;
}

LuaLink_RaySceneQuery::~LuaLink_RaySceneQuery(void) {
	mResult = NULL;
}

bool LuaLink_RaySceneQuery::lua_executeWorldIntersection(Ogre::Vector3* pos, Ogre::Vector3* dir){
	
	Ogre::Ray ray(*pos, *dir);
	mRaySceneQuery->setRay(ray);
	Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
	Ogre::RaySceneQueryResult::iterator itr = result.begin();

	if(itr != result.end() && itr->worldFragment){
		mResult = new Ogre::Vector3(itr->worldFragment->singleIntersection.x,itr->worldFragment->singleIntersection.y,itr->worldFragment->singleIntersection.z);
		return true;
	}

	return false;

}

Ogre::Vector3* LuaLink_RaySceneQuery::lua_getResult(){
	return mResult;
}